from rest_framework import serializers

from goods.models import SPU, SPUSpecification, SpecificationOption


class SPUSimpleSerializer(serializers.ModelSerializer):
    """SPU序列化器类"""
    class Meta:
        model = SPU
        fields = ('id', 'name')

class SpecOptionSerializer(serializers.ModelSerializer):
    class Meta:
        model = SpecificationOption
        fields = ('id', 'value')

class SPUSpecSerializer(serializers.ModelSerializer):
    """规格序列化器类"""
    # 使用自定义序列化器类进行嵌套
    options = SpecOptionSerializer(label='选项',many=True)

    class Meta:
        model = SPUSpecification
        fields = ('id','name','options')


